package com.graduation.roombooking.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.graduation.roombooking.mapper.EquipmentMapper;
import com.graduation.roombooking.pojo.Equipment;
import com.graduation.roombooking.service.IEquipmentService;
import com.graduation.roombooking.vo.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author ZhaoXinyi
 * @since 2022-05-04
 */
@Service
public class EquipmentServiceImpl extends ServiceImpl<EquipmentMapper, Equipment> implements IEquipmentService {

    @Autowired
    private EquipmentMapper equipmentMapper;

    @Override
    public RespBean getList(String companyName) {
        return RespBean.success(equipmentMapper.getList(companyName));
    }

    @Override
    public RespBean addOne(AddEquipmentVo addEquipmentVo, String companyName) {
        if(equipmentMapper.addOne(addEquipmentVo,companyName)<1){
            return RespBean.error(RespBeanEnum.INSERT_ERROR,"添加失败，请规范输入数据");
        }
        return RespBean.success();
    }

    @Override
    public RespBean updateEquipment(UpdateEquipmentVo updateEquipmentVo, String companyName) {
        if(equipmentMapper.updateEquipment(updateEquipmentVo,companyName)<1){
            return RespBean.error(RespBeanEnum.INSERT_ERROR,"添加失败，请规范输入数据");
        }
        return RespBean.success();
    }

    @Override
    public RespBean deleteOne(Integer id, String companyName) {
        if(equipmentMapper.deleteOne(id,companyName)<1){
            return RespBean.error(RespBeanEnum.DELETE_ERROR,"请确认是否是本部门设备");
        }
        return RespBean.success();
    }

    @Override
    public RespBean unionQuery(EquipmentUnionQueryVo unionQueryVo, String companyName) {
        return RespBean.success(equipmentMapper.unionQuery(unionQueryVo,companyName));
    }

    @Override
    public RespBean getEquipmentMultipleChoice(String companyName) {
        try {
            return RespBean.success(equipmentMapper.getEquipmentMultipleChoice(companyName));
        }
        catch (Exception e){
            e.printStackTrace();
        }
        return RespBean.error(RespBeanEnum.BIN_ERROR,"我也不知道什么错，反正就是错了");
    }
}
